// components/date-picker/data-picker.js
var util = require('../../utils/util.js');
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    "startDate": String,
    "endDate": String
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    //当开始日期改变的时候
    bindDateChange: function(e) {
      let startDate = '';
      let endDate = '';
      if(e.target.dataset.type==='1'){
        startDate = e.detail.value;
        endDate = this.data.endDate;
      } else {
        startDate = this.data.startDate;
        endDate  = e.detail.value;
      }
      this.setData({
        startDate: startDate
      });
      this.setData({
        endDate: endDate
      });
      if (startDate === '开始日期' || endDate==='结束日期'){
        this.triggerEvent('changeDate');
      } else {
        if (util.compareTime(startDate, endDate)) {
          let date = {
            start_date: startDate,
            end_date: endDate
          };
          this.setData({
            startDate: startDate
          });
          this.setData({
            endDate: endDate
          });
          this.triggerEvent('changeDate', date);
        } else {
          wx.showToast({
            title: '开始日期不能大于结束日期和当前日期',
            icon: 'none'
          })
        }
      }
      
    },
  }
})